package com.ericpol.pageobject;

import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Page {

	protected WebDriver driver;

	public Page(WebDriver driver) {
		this.driver = driver;
	}
	
	protected void openUrl(String  baseUrl) {
		driver.get(baseUrl);
	}

	protected void findAndClick(By by) {
		driver.findElement(by).click();
	}
	
	protected void insertText(By by, String text) {
		WebElement element = driver.findElement(by);
		element.clear();
		element.sendKeys(text);
	}
	
	protected boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch(NoSuchElementException e) {
			return false;
		}
	}
	
	protected boolean isTextPresent(String expected) {
		String pageSource = driver.getPageSource();
		return pageSource.contains(expected);
	}
}